<?php
require_once 'loader.php';
require_once 'Mobitv/Cronjobs/Alert.php';

$fromDate = '2010-01-01';
$toDate = '2010-05-01';

// Gia kenh addon
$channelPrice = array();
$db->query("SELECT name, price FROM channel");
$rows = $db->fetchRowset();
foreach($rows AS $row)
{
    $channelPrice[$row['name']] = intval($row['price']);
}

$db = Vega_Dao::factory('Mobitv_Common')->mydb;
$db->query("select * from transaction where action='monfee' and charge>0 and created_time>='$fromDate' and created_time<'$toDate'");
$rows = $db->fetchRowset();
if($rows)
{
    foreach($rows AS $row)
    {
        $requestId = $row['request_id'];
        $msisdn = $row['msisdn'];
        $content = $row['content'];
        $createdTime = $row['created_time'];
        
        $db->query("INSERT INTO transaction_monfee SET request_id='$requestId', msisdn='$msisdn', action='monfee', charge=35000, created_time='$createdTime'");

        if($content)
        {
            $addonChannels = explode(",", $content);
            foreach($addonChannels AS $item)
            {
                $price = $channelPrice[$item];
                $db->query("INSERT INTO transaction_monfee SET request_id='$requestId', msisdn='$msisdn', action='addon', content='$item', charge=$price, created_time='$createdTime'");
            }
        }

        echo $requestId . "\n";
    }
}
